package com.ding.easycontroller.work;

import lombok.Data;

@Data
public abstract class Script {

    //获取脚本描述
    protected String description;

    //获取js脚本
    protected String js;

    protected String id;

    protected String type;

    public boolean equals(Object obj) {

        if (obj == null) {
            return false;
        }

        if (obj instanceof Script) {
            if (id == null) {
                return ((Script) obj).getId() == null;
            }
            return id.equals(((Script) obj).getId());
        }

        return false;
    }

    private boolean initialized = false;

    public void init() {
        if (!initialized) {
            doInit();
            initialized = true;
            destroyed = false;
        }
    }

    protected abstract void doInit();

    private boolean destroyed = false;

    public void destroy() {
        if (!destroyed) {
            doDestroy();
            destroyed = true;
            initialized = false;
        }
    }

    protected abstract void doDestroy() ;

}
